home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
MCASM.RAR
/
MC_ASM.EXE
/
WROX_ASM
/
CH12
/
RASTFONT
/
PUTSTR.ASM
< prev
Wrap
Assembly Source File
|
1994-11-16
|
7KB
|
429 lines
; This program defines procedure OverlapString, that displays
; a text string on EGA/VGA in 16 colors graphics mode using specified
; raster font.
.model large
.data
BytesPerLine dw 80
_FontColor db 15
; Output is clipped to the view port defined below
ViewPortleft dw 0
ViewPorttop dw 0
ViewPortright dw 639
ViewPortbottom dw 479
public _DispalyString
public _FontColor
.code
; Call: DispalyString( int X, int Y, void* StrVar,
; void* CurrentFontPtr, int CharHeight, int CharWidth);
X EQU word ptr [bp+6]
Y EQU word ptr [bp+8]
StrVar EQU dword ptr [bp+10]
StrVarAOffs EQU word ptr [bp+10]
CurrentFontPtr EQU dword ptr [bp+14]
CharHeight EQU byte ptr [bp+18]
CharWidth EQU byte ptr [bp+20]
; Local variables:
OurCharHeight EQU byte ptr [bp-1]
OurCharWidth EQU byte ptr [bp-2]
VBOffs EQU word ptr [bp-4]
BChar EQU byte ptr [bp-5]
OurStrLength EQU byte ptr [bp-6]
BCMask EQU byte ptr [bp-7]
ECMask EQU byte ptr [bp-8]
DecBytesPerLine EQU word ptr [bp-10]
SolidFColor EQU byte ptr [bp-11]
AbsCharHeight EQU byte ptr [bp-12]
VideoSelector EQU word ptr [bp-14]
_DispalyString proc far
push bp
mov bp,sp
sub sp,14
push ds
push di
push si
; Initialize locals
mov ax,0a000h
mov VideoSelector,ax
mov ax,@data
mov es,ax
mov ax,BytesPerLine
dec ax
mov DecBytesPerLine,ax
mov al,_FontColor
mov SolidFColor,al
mov VBOffs,0
; Check vertical coordinates for clipping
xor bx,bx
mov si,ViewPortbottom
mov di,ViewPorttop
mov ax,Y
add ax,di
mov Y,ax
cmp ax,si
jle VCE1 ; check string top & ViewPort bottom
jmp EC10 ; string invisible
VCE1:
mov bl,CharHeight
mov dl,bl
cmp ax,di
jge VCE2 ; check string top & ViewPort top
mov dx,di
sub dx,ax
mov VBOffs,dx
neg dl
add dl,bl
mov Y,di
VCE2:
add ax,bx
dec ax
cmp ax,di
jge VCE3 ; check string bottom & ViewPort top
jmp EC10 ; string invisible
VCE3:
sub ax,si
jl VCE4 ; check string bottom & ViewPort bottom
sub dl,al
VCE4:
mov OurCharHeight,dl
; Check horisontal coordinates
mov BCMask,0
mov si,ViewPortRight
mov cx,ViewPortleft
mov ax,X
add ax,cx
mov X,ax
cmp ax,si
jle HCE1 ; check string left & ViewPort right
jmp EC10 ; string invisible
HCE1:
mov BChar,bl ; store AbsCharHeight
les bx,StrVar ; ES:BX -> String
push bx
mov dl,0
; Find terminating zero and initialize char counter
find_0:
mov dh,es:[bx]
or dh,dh
jz end_line
inc dl
inc bx
jmp short find_0
end_line:
pop bx
mov dh,dl
mov OurStrLength,dh ; char counter
mov dl,CharWidth
mov OurCharWidth,dl
mov ECMask,dl
mov di,ax
cmp ax,cx
jge HCE2 ; check string left & ViewPort left
neg ax
add ax,cx
div dl
WCut:
cmp al,dh
jl HCPE
jmp EC10 ; string invisible
HCPE:
mov di,cx
and ah,ah
je BMzero
mov BCMask,ah
inc al
BMzero:
xor ah,ah
mov cl,dh
sub cl,al
mov OurStrLength,cl
add bx,ax
HCE2:
mov cl,OurStrLength
mov al,dh
mul dl
add ax,X
dec ax
sub ax,si
jle AllChEnd
div dl
cmp ah,0
je WCut2
inc al
sub ECMask,ah
WCut2:
sub cl,al
mov OurStrLength,cl
AllChEnd:
push ds
mov StrVarAOffs,bx
mov dx,3ceh
mov ax,0805h
out dx,ax ; Set write mode 0 (normal)
mov ax,0ff01h
out dx,ax ; Enable Set/Reset
mov al,0
mov ah,SolidFColor
out dx,ax ; Set color
mov al,8
out dx,al ; Set register index to Mask Register
; Calulate start offset in video buffer
mov bl,cl
mov ax,Y
mul BytesPerLine ; YCoord * BytesPerLine
mov dx,di
mov di,ax
mov ax,dx
mov cl,3
shr ax,cl
mov cx,dx
and cx,7
add di,ax
lds si,CurrentFontPtr
add si,VBOffs
mov al,BChar
mov AbsCharHeight,al
mov al,ECMask
sub al,OurCharWidth
or al,BCMask
jnz CharCuting ; Clip to view port
HSpeedDC:
mov dx,3cfh
mov ax,StrVarAOffs
xor bh,bh
add bx,ax
xchg bx,ax
mov VBOffs,ax
; Main loop (string output)
PutEGALoop:
push si
push es
push di
call PutEGAChar ; char by char
pop di
pop es
pop si
add cl,OurCharWidth
cmp cl,08
jl OldVByte
inc di
and cl,07
OldVByte:
inc bx
cmp bx,VBOffs
jl PutEGALoop ; Next char
By_By:
; Restore default ports values
mov dx,3ceh
mov ax,0001H
out dx,ax
mov ax,0FF08H
out dx,ax
mov ax,0005
out dx,ax
pop ds
EC10:
pop si
pop di
pop ds
mov sp,bp
pop bp
ret ; Return from OverlapString
; Character fragment output (clipped)
CharCuting:
or bl,bl
jl EandBcon
mov BChar,cl
mov X,di
mov dh,BCMask
or dh,dh
jz EMaskDrwng
mov dl,OurCharWidth
mov bx,StrVarAOffs
dec bx
push es
push si
call SpecPutEGAChar
pop si
pop es
mov di,X
add cl,OurCharWidth
sub cl,BCMask
cmp cl,08
jl EMDg
inc di
and cl,07
mov X,di
EMDg:
mov BChar,cl
EMaskDrwng:
mov dl,ECMask
mov al,OurCharWidth
cmp dl,al
je RestorePars
mov dh,OurStrLength
mul dh
mov dh,al
mov ch,cl
mov cl,03
shr ax,cl
add di,ax
and dh,07
add dh,ch
mov al,dh
cbw
shr ax,cl
add di,ax
mov cl,dh
and cl,07
xor dh,dh
mov bx,StrVarAOffs
add bl,OurStrLength
adc bh,00
push es
push si
call SpecPutEGAChar
pop si
pop es
mov di,X
mov cl,BChar
RestorePars:
mov bl,OurStrLength
or bl,bl
jz ABy_By
NIncDI:
jmp HSpeedDC
EandBcon:
mov dh,BCMask
mov dl,ECMask
mov bx,StrVarAOffs
dec bx
push es
call SpecPutEGAChar
pop es
ABy_By:
jmp By_By
_DispalyString endp
;--------- PutEGAChar
PutEGAChar proc near
xor ax,ax
mov al,es:[bx]
mul AbsCharHeight
mov ch,OurCharHeight
add si,ax
mov es,VideoSelector
or cl,cl
jnz NonByteAlign
ByteAlignLoop:
mov al,[si]
out dx,al
xchg es:[di],al
inc si
add di,BytesPerLine
dec ch
JNZ ByteAlignLoop
jmp Happy
NonByteAlign:
xor al,al
mov ah,[si]
shr ax,cl
xchg al,ah
out dx,al
xchg es:[di],al
inc di
mov al,ah
out dx,al
xchg es:[di],al
inc si
add di,DecBytesPerLine
dec ch
jnz NonByteAlign
Happy:
ret
PutEGAChar endp
;--------------- SpecPutEGAChar
SpecPutEGAChar proc near
xor ax,ax
mov al,es:[bx]
mul AbsCharHeight
mov ch,OurCharHeight
add si,ax
mov es,VideoSelector
mov ax,0FF00H
xchg cl,dl
shr ah,cl
not ah
mov bl,ah ;Zero-shr mask
mov bh,dh
mov cl,dl
mov dx,3cfh
or cl,cl
jnz SNonByteAlign
SByteAlignLoop:
mov al,[si]
and al,bl
xchg bh,cl
shl al,cl
xchg bh,cl
shr al,cl
out dx,al
xchg es:[di],al
inc si
add di,BytesPerLine
dec ch
jnz SByteAlignLoop
ret
SNonByteAlign:
xor al,al
mov ah,[si]
and ah,bl
xchg bh,cl
shl ax,cl
xchg bh,cl
shr ax,cl
xchg al,ah
out dx,al
xchg es:[di],al ; first half of char
inc di
mov al,ah
out dx,al
xchg es:[di],al ; last half of char
inc si
add di,DecBytesPerLine
dec ch
jnz SNonByteAlign
ret
SpecPutEGAChar endp
end